#ifndef THREAD_POOL_H
#define THREAD_POOL_H

#include <pthread.h>

typedef struct thread_pool_task {
    void (*func)(void*);
    void* arg;
    struct thread_pool_task* next;
} thread_pool_task_t;

typedef struct thread_pool_task_queue {
    thread_pool_task_t* head;
    thread_pool_task_t* tail;
    int count;
    pthread_mutex_t lock;
} thread_pool_task_queue_t;

typedef struct thread_pool {
    pthread_mutex_t lock;
    pthread_cond_t cond;
    pthread_t* threads;
    thread_pool_task_queue_t* queue;
    int thread_count;
    int keepalive;
} thread_pool_t;

thread_pool_t* thread_pool_create(int thread_count);
void thread_pool_destroy(thread_pool_t* pool);
void thread_pool_submit(thread_pool_t* pool, void(*func)(void*), void* arg);

#endif
